<?php $this->_extends('../_layouts/default_layout'); ?>
<?php $this->_block('contents'); ?>
<fieldset><legend>查询条件</legend>
<form method="get" action="">
<?include(Q::ini('custom_system/elements_dir') . 'searchform_element.php');?>
<table class="form_table">
<tbody>
<tr>
	<th>查询类型</th>
	<td>
		<input ra_group="on" tar_group='zen_cart_sites' type="radio" name="search_type" id="zen_cart_sites_rad" value="zen_cart_sites" <?php if ($currentSearchType == 'zen_cart_sites') echo "checked='checked'"; ?> />
		<label for="zen_cart_sites_rad"> Zencart 独立站注册客户 </label>
		<input ra_group="on" tar_group='ebay_stores' type="radio" name="search_type" id="ebay_stores_rad" value="ebay_stores" <?php if ($currentSearchType == 'ebay_stores') echo "checked='checked'"; ?> />
		<label for="ebay_stores_rad"> eBay 订单客户（按产品分类） </label>
	</td>
</tr>
<tr ra_group='rel' tar_group='zen_cart_sites' <?php if ($currentSearchType != 'zen_cart_sites') echo "hidden";?>>
	<th>网站</th>
	<td>
		<select name="shop_id">
			<option value="53">iWowcase.com</option>
		</select>
	</td>
</tr>
<!-- <tr ra_group='rel' tar_group='zen_cart_sites' <?php if ($currentSearchType != 'zen_cart_sites') echo "hidden";?>>
	<th>客户来源</th>
	<td>
		<input type="radio" name="reg_source" id="reg_source_all_rad" value="all" <?php //if ($currentRegSource == 'all') echo "checked='checked'"; ?> />
		<label for="reg_source_all_rad"> 全部 </label>
		<input type="radio" name="reg_source" id="reg_source_site_rad" value="site" <?php //if ($currentRegSource == 'site') echo "checked='checked'"; ?> />
		<label for="reg_source_site_rad"> 站内 </label>
		<input type="radio" name="reg_source" id="reg_source_ebay_rad" value="ebay" <?php //if ($currentRegSource == 'ebay') echo "checked='checked'"; ?> />
		<label for="reg_source_ebay_rad"> eBay </label>
	</td>
</tr> -->
<tr ra_group='rel' tar_group='ebay_stores' <?php if ($currentSearchType != 'ebay_stores')  echo "hidden";?>>
	<th>分类</th>
	<td>
		<select name="cat_id">
			<option value=''> - 所有分类 -  </option>
			<?foreach ($categories as $k => $v):?>
			<option value="<?=$v["id"]?>" <?php if ($currentCatID == $v["id"]) echo "selected='selected'"; ?>><?=$v["name"]?></option>
			<?php endforeach ?>
		</select>
	</td>
</tr>
<tr ra_group='rel' tar_group='ebay_stores' <?php if ($currentSearchType != 'ebay_stores')  echo "hidden";?>>
	<th>邮件服务商</th>
	<td>
		<?foreach ($mailServer as $v):?>
		<input type="checkbox" name="mail_server[]" id="cb_mail_server_<?=$v?>" value="<?=$v?>" <?php if (in_array($v, $currentMailServer)) echo "checked='checked'"; ?> />
		<label for="cb_mail_server_<?=$v?>" ><?=$v?></label> &nbsp;&nbsp;&nbsp;&nbsp;
		<?php endforeach ?>
	</td>
</tr>
<tr>
	<th>注册(初次订单)日期</th>
	<td colspan="3">
		<input type="text" value="<?=$bdate?>" name="bdate" class="datepicker" /> to
		<input type="text" value="<?=$edate?>" name="edate" class="datepicker" />
	</td>
</tr>
<tr>
	<th>是否同步列表</th>
	<td colspan="3">
		<input cb_group="on" tar_group='need_sync' type="checkbox" name="need_sync" id="need_sync_cb" value="1" <?php if ($needSync == '1') echo "checked='checked'"; ?> />
		<label for="need_sync_cb"> 同步 </label>
	</td>
</tr>
<tr cb_group='rel' tar_group='need_sync' <?php if ($needSync != '1') echo "hidden";?>>
	<th>选择账号</th>
	<td>
		<select name="bmail_account"  onchange='location.href = location.href.replace(/\&bmail_account\=[^\&]*/g,"") + "&bmail_account=" + this.value; '>
			<option value='' > -- 请选择一个账号 --</option>
			<?foreach ($bmailAccount as $k => $v):?>
			<option value="<?=$k?>" <?php if ($currentAccount == $k) echo "selected='selected'"; ?>><?=$k?></option>
			<?php endforeach ?>
		</select>
	</td>
</tr>
<tr>
<tr cb_group='rel' tar_group='need_sync' <?php if (!isset($need_sync)) echo "hidden";?>>
	<th>客户邮件列表</th>
	<td><select name="to_listid" id="to_listid" >
	<option value=''> -- 请选择一个客户邮件列表 -- </option>
	<?foreach ($toMailGroup as $v):?>
	<option value='<?=$v['id'];?>' <?php if ($toListID == $v['id']) echo "selected='selected'"; ?> > <?=$v["listname"];?> (<?=$v["contactcount"];?>) </option>	
	<?php endforeach ?>
	</select> <span class="red">*</span> 
	</td>
</tr>
<tr>
	<td></td>
	<td><input type="submit" value="查询" class="button"></td>
</tr>
</tbody></table>
</form>
</fieldset>

<?php if ( $currentSearchType == "zen_cart_sites" ) { ?>

 <table width="100%" class="list_table" >
        <tr>
            <th rowspan="2">#</th>
            <th rowspan="2" >同步状态</th>
            <th rowspan="2" >注册来源</th>
            <th rowspan="2" >邮箱</th>
            <th rowspan="2" >全名</th>
            <!-- <th colspan="3">eBay订单状态</th> -->
            <th colspan="4">独立站订单状态</th>
        </tr>
        <tr>
            <!-- <th >总数</th>
            <th >总金额</th>
            <th width="85">初次时间</th> -->
            <th >总数</th>
            <th >总金额</th>
            <th width="85" >注册时间</th>
            <th width="85" >最后登录时间</th>
        </tr>
        
        <?foreach ($customerMailList as $k => $v):?>
        <?php if ($currentRegSource != 'all' && $v["reg_source"] != $currentRegSource) continue; ?>
        <tr>
            <th><?=$k?></th>
            <td><?=$v["sync_status"]?></td>
            <td><?=$v["reg_source"]?></td>
            <td><?=$v["email"]?></td>
            <td><?=$v["first_name"]." ".$v["last_name"]?></td>
            <!-- <td><?//=$v["ebay_order_count"]?></td>
            <td><?//=$v["ebay_order_amount"]?></td>
            <td><?//=$v["ebay_first_order_time"]?></td> -->
            <td><?=$v["site_order_count"]?></td>
            <td><?=$v["site_order_amount"]?></td>
            <td><?=$v["site_reg_time"]?></td>
            <td><?=$v["site_last_login_time"]?></td>
        </tr>
        <?endforeach;?>
</table>

<?php } else if ( $currentSearchType == "ebay_stores" ) { ?>

 <table width="100%" class="list_table" >
        <tr>
            <th >#</th>
            <th >同步状态</th>
            <th >客户eBayID/Name</th>
            <th >邮箱服务商</th>
            <th >邮箱</th>
            <th >订单ID</th>
            <th >产品分类</th>
            <th >店铺eBayID</th>
            <th >最近订单时间</th>
            <th >最近发货时间</th>
        </tr>
        
        <?foreach ($customerMailList as $k => $v):?>
        <tr>
            <th><?=$k?></th>
            <td><?=$v["sync_status"]?></td>
            <td><?=$v["customer_ebay_id"]?><br /><?=$v["fullname"]?></td>
            <td><?=$v["email_server"]?></td>
            <td><?=$v["email"]?></td>
            <td><?=$v["order_id"]?></td>
            <td><?=$v["category_name"]?></td>
            <td><?=$v["shop_ebay_id"]?></td>
            <td><?=$v["order_time"]?></td>
            <td><?=$v["shipped_time"]?></td>
        </tr>
        <?endforeach;?>
</table>

<?php } ?>
<script type="text/javascript">
$(".datepicker").datepicker({dateFormat:'yy-mm-dd',changeMonth:true});
$("input[cb_group=on]").click(function() {
	var ntg = $(this).attr("tar_group");
	var now_status = $(this).attr("checked");
	if (now_status == "checked") $("[cb_group=rel][tar_group="+ntg+"]").show();
	else $("[cb_group=rel][tar_group="+ntg+"]").hide();
});

var now_ra_tar_group;

$("input[ra_group=on]").click(function() {
	now_ra_tar_group = $(this).attr("tar_group");

	$("input[ra_group=on]").each(function() { 
		var this_tar_group = $(this).attr("tar_group");
		if (now_ra_tar_group == this_tar_group) $("[ra_group=rel][tar_group="+this_tar_group+"]").show();
		else $("[ra_group=rel][tar_group="+this_tar_group+"]").hide();
	})
	
});


</script>
<?php $this->_endblock(); ?>